package org.javaboy.vhr.controller.emp;

import org.javaboy.vhr.model.Department;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.Employeeremove;
import org.javaboy.vhr.model.Position;
import org.javaboy.vhr.service.EmployeeecService;
import org.javaboy.vhr.service.EmployeeremoveService;
import org.javaboy.vhr.vo.RespBean;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Author: cheng
 */
@RestController
@RequestMapping("/employee/move")
public class EmpRemoveController {

    @Autowired
    EmployeeremoveService employeeremoveService;

    @GetMapping("/")
    public RespPageBean getEmployeeecByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Employeeremove employeeremove, Date[] beginDateScope) {
        return employeeremoveService.getEmployeeremoveByPage(page,size,employeeremove,beginDateScope);
    }

    @GetMapping("/getTotalDepartment")
    public RespBean getTotalDepartment(){
        List<Department> departmentList = employeeremoveService.getTotalDepartment();
        if(departmentList !=null){
            return RespBean.ok("查询成功",departmentList);
        }else return RespBean.error("查询失败");
    }

    @GetMapping("/getTotalPosition")
    public RespBean getTotalPosition(){
        List<Position> positions = employeeremoveService.getTotalPosition();
        if(positions !=null){
            return RespBean.ok("查询成功",positions);
        }else return RespBean.error("查询失败");
    }

    @PostMapping("/add")
    public RespBean add(@RequestBody Employeeremove employeeremove){
        int i = employeeremoveService.add(employeeremove);
        if(i == 0) {
            return RespBean.error("操作失败");
        }else return RespBean.ok("操作成功");
    }

    @PutMapping("/update")
    public RespBean updateEmp(@RequestBody Employeeremove employeeremove) {
        int result = employeeremoveService.update(employeeremove);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteEcById(@PathVariable Integer id) {
        int result = employeeremoveService.delete(id);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }
}
